﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace BDH.PRE.Form
{
    using DAL.Entities;
    public partial class FrmDongia_Popup : DevExpress.XtraEditors.XtraForm
    {
        public int id_nhatro;
        BLL.DongiaBLL _bll = new BLL.DongiaBLL();

        public FrmDongia_Popup()
        {
            InitializeComponent();
        }

        private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var o = new Dongia()
            {
                giadien = Convert.ToDecimal("0" + txtGiadien.EditValue),
                gianuoc = Convert.ToDecimal("0" + txtGianuoc.EditValue),
                ngay = dteNgay.DateTime,
                nhatro_id = id_nhatro
            };
            var ok = _bll.Insert(o);
            if (ok)
            {
                FrmDongia_Popup_Load(sender, null);
                ResetText();
            }
        }

        private void btnCancel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Dispose();
            this.Close();
        }

        private void FrmDongia_Popup_Load(object sender, EventArgs e)
        {
            var dtb = _bll.Select(id_nhatro);
            if (dtb != null)
                dgDongia.DataSource = dtb;
            txtGiadien.Focus();
            dteNgay.EditValue = DateTime.Now;
        }

        private void ResetText()
        {
            txtGiadien.EditValue = null;
            txtGianuoc.EditValue = null;
            dteNgay.EditValue = DateTime.Now;
            txtGiadien.Focus();
        }



    }
}